import { getCombinedWaybillsApi } from "@/api/waybillManagement/businessWaybill/waybillQuotation";
import { message } from "ant-design-vue";
import { Ref } from "vue";
export default function OperationHook(state: { drawerOpts: Base.DrawerOpts; passData: Ref<WaybillQuotation.ListRows>; dialogOpts: Base.DialogOpts; formState: Ref<any>; init: (id: string) => void }) {
  const { drawerOpts, dialogOpts, passData, formState } = state;
  // 查看发票
  const showInvoiceHandle = () => {
    drawerOpts.width = "1200px";
    drawerOpts.title = "查看发票";
    drawerOpts.type = 1;
    drawerOpts.passData = formState.value;
    drawerOpts.component = "ShowInvoice";
    drawerOpts.visible = true;
  };
  // 修改客户备注
  const modifyRemarkHandle = () => {
    dialogOpts.title = `修改客户备注`;
    dialogOpts.width = "520px";
    dialogOpts.type = 1;
    dialogOpts.component = "ModifyRemark";
    dialogOpts.passData = formState;
    dialogOpts.visible = true;
  };
  // 修改客户备注
  const modifyInnerRemarkHandle = () => {
    dialogOpts.title = `修改内部备注`;
    dialogOpts.width = "520px";
    dialogOpts.type = 2;
    dialogOpts.component = "ModifyRemark";
    dialogOpts.passData = formState;
    dialogOpts.visible = true;
  };
  // 查看材积明细
  const showBoxInfoHandle = () => {
    drawerOpts.width = "1200px";
    drawerOpts.title = "查看材积明细";
    drawerOpts.type = 1;
    drawerOpts.passData = passData.value;
    drawerOpts.component = "BoxInfo";
    drawerOpts.visible = true;
  };
  // 合并报关详情
  const cancelMergeDeclarationHandle = () => {
    getCombinedWaybillsApi({ billingWaybillNum: passData.value.billingWaybillNum }).then((res: any) => {
      const { code, data } = res;
      if (code === 200 && data.billingWaybillNum) {
        dialogOpts.title = `取消合并报关`;
        dialogOpts.width = "500px";
        dialogOpts.type = 3;
        dialogOpts.component = "CustomsClearance";
        dialogOpts.passData = [passData.value];
        dialogOpts.visible = true;
      } else {
        return message.error("运单暂无合并报关信息!");
      }
    });
  };
  return {
    showInvoiceHandle,
    modifyRemarkHandle,
    modifyInnerRemarkHandle,
    showBoxInfoHandle,
    cancelMergeDeclarationHandle
  };
}
